package com.zoctan.api.mapper;

import com.zoctan.api.entity.AccountRole;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

/**
 * @author Zoctan
 * @date 2018/06/09
 */
@Mapper
@Repository
public interface AccountRoleMapper {

  /**
   * 更新用户角色
   *
   * @param accountRole 用户角色
   */
  @Update(
      "UPDATE account_role SET role_id = #{accountRole.roleId} WHERE account_id = #{accountRole.accountId}")
  void updateRoleIdByAccountId(@Param("accountRole") AccountRole accountRole);
  
  @Insert("insert into account_role (account_id, role_id) values (${accountId}, ${roleId}) ")
  void insertSelective(AccountRole accountRole);
  
  @Select("select * from account_role where account_id=${accountId} ")
  AccountRole selectByAccountId(@Param("accountId") Long accountId);
}
